package com.csu.csumall.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csu.csumall.VO.OrderDetailVO;
import com.csu.csumall.entity.*;
import com.csu.csumall.mapper.OrderItemMapper;
import com.csu.csumall.mapper.OrderMapper;
import com.csu.csumall.mapper.PayInfoMapper;
import com.csu.csumall.mapper.ShippingMapper;
import com.csu.csumall.service.IOrderDetailVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

@Service("orderDetailVOService")
public class OrderDetailVOServiceImp implements IOrderDetailVOService {

    private final OrderMapper orderMapper;
    private final ShippingMapper shippingMapper;
    private final OrderItemMapper orderItemMapper;
    private final PayInfoMapper payInfoMapper;

    @Autowired
    public OrderDetailVOServiceImp(OrderMapper orderMapper, ShippingMapper shippingMapper,
                                   OrderItemMapper orderItemMapper, PayInfoMapper payInfoMapper) {

        this.orderMapper = orderMapper;
        this.shippingMapper = shippingMapper;
        this.orderItemMapper = orderItemMapper;
        this.payInfoMapper = payInfoMapper;

    }


    @Override
    public OrderDetailVO getOne(User user, BigInteger orderNo) {

        Order order = orderMapper.selectOne(new QueryWrapper<Order>().eq("order_no", orderNo));
        Shipping shipping = shippingMapper.selectById(order.getId());
        List<OrderItem> orderItems = orderItemMapper.selectList(new QueryWrapper<OrderItem>().eq("order_no", orderNo));
        PayInfo payInfo = payInfoMapper.selectOne(new QueryWrapper<PayInfo>().eq("order_no", orderNo));

        return new OrderDetailVO(order, shipping, orderItems, payInfo);
    }
}
